package com.max.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.max.base.BaseController;
import com.max.common.R;
import com.max.entity.TimeSlot;
import com.max.service.ITimeSlotService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Objects;

@Api(tags = "会议室时间段管理相关接口", value = "会议室时间段管理相关接口")
@RequestMapping(value = "/timeSlot")
@RestController
public class TimeSlotController extends BaseController {


    @Autowired
    private ITimeSlotService timeSlotService;


    @ApiOperation("查询会议室时间段列表")
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public R<List<TimeSlot>> list(TimeSlot timeSlot) {
        startPage();
        List<TimeSlot> list = timeSlotService.list(new LambdaQueryWrapper<TimeSlot>()
                .eq(!Objects.isNull(timeSlot.getRoomId()), TimeSlot::getRoomId, timeSlot.getRoomId())
                .eq(!Objects.isNull(timeSlot.getTimeNum()), TimeSlot::getTimeNum, timeSlot.getTimeNum())
                .eq(!Objects.isNull(timeSlot.getUseDate()), TimeSlot::getUseDate, timeSlot.getUseDate())
                .eq(!Objects.isNull(timeSlot.getRoomState()), TimeSlot::getRoomState, timeSlot.getRoomState())
        );
        return R.ok(list);
    }

    @ApiOperation("添加会议室时间段")
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public R<?> addTimeSlot(@RequestBody TimeSlot timeSlot) {
        boolean save = timeSlotService.save(timeSlot);
        return R.result(save);
    }

    @ApiOperation("根据会议室时间段ID更新会议室时间段")
    @RequestMapping(value = "/updateById", method = RequestMethod.POST)
    public R<?> updateTimeSlotById(@RequestBody TimeSlot timeSlot) {
        boolean update = timeSlotService.updateById(timeSlot);
        return R.result(update);
    }

    @ApiOperation("根据会议室时间段ID删除会议室时间段")
    @RequestMapping(value = "/deleteById/{id}", method = RequestMethod.POST)
    public R<?> deleteTimeSlotById(@PathVariable("id") Long id) {
        boolean delete = timeSlotService.removeById(id);
        return R.result(delete);
    }


}
